KmmResult

For easy use under iOS, we need a class like Result that is not a value class (which is unsupported in Kotlin/Native)

Constructors

Link copied to clipboard
constructor(value: T)

Creates a success result from the given value

constructor(failure: Throwable)

Creates a failure result from the given failure

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns true if this instance represents a failed outcome. In this case isSuccess returns false.

Link copied to clipboard

Returns true if this instance represents a successful outcome. In this case isFailure returns false.

Functions

Link copied to clipboard

Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.

Link copied to clipboard
inline fun <R> fold(onSuccess: (value: T) -> R, onFailure: (exception: Throwable) -> R): R

Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.

Link copied to clipboard
inline fun getOrElse(onFailure: (exception: Throwable) -> T): T

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.

Link copied to clipboard
fun getOrNull(): T?

Returns the encapsulated value if this instance represents success or null if it is failure.

Link copied to clipboard
fun getOrThrow(): T

Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.

Link copied to clipboard
inline fun <R> map(block: (T) -> R): KmmResult<R>

Transforms this KmmResult's success-case according to block and leaves the failure case untouched (type erasure FTW!)

Link copied to clipboard
inline fun mapFailure(block: (Throwable) -> Throwable): KmmResult<T>

Transforms this KmmResult's failure-case according to block and leaves the success case untouched (type erasure FTW!)

Link copied to clipboard
inline fun <R> onFailure(block: (error: Throwable) -> R)

singular version of fold's onFailure

Link copied to clipboard
inline fun <R> onSuccess(block: (value: T) -> R)

singular version of fold's onSuccess

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun unwrap(): Result<T>

Returns a Result equivalent of this KmmResult